﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.PersonnelCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.PersonnelHandlers
{
    /// <summary>
    /// 人员基本信息添加--中介者
    /// </summary>
    public class PersonnelCreateHandlers : IRequestHandler<PersonnelCreateCommand, Results<int>>
    {
        private readonly IUserInfoService userInfoService;
        private readonly IMapper mapper;

        public PersonnelCreateHandlers(IUserInfoService userInfoService, IMapper mapper)
        {
            this.userInfoService = userInfoService;
            this.mapper = mapper;
        }
        public async Task<Results<int>> Handle(PersonnelCreateCommand request, CancellationToken cancellationToken)
        {
            // throw new NotImplementedException();
            //类型转换
            var entity = mapper.Map<Personnel>(request);

            //添加
            var res=await  userInfoService.AddPersonnel(entity);

            return Results<int>.DataResult(res);




		}
    }
}
